using System;
using System.Collections.Generic;
using UnityEngine;

namespace Scene.Scripts
{
    [Serializable]
    public class GlobalAssets : MonoBehaviour
    {
        [SerializeField] private List<SceneBox.ScenePoint> mGlobalPoints;
        [SerializeField] private List<SceneBox> mGlobalBoxes;
        private Bounds _sceneBounds;

#if UNITY_EDITOR
        [SerializeField,Header("展示场景物件Bounds")] 
        public bool mShowSceneObjBounds = false;

        [SerializeField, Header("展示SceneBoxBounds")]
        public bool mShowSceneBoxBounds = false;

        [SerializeField, Header("展示type")]
        private SceneBox.AssetDetailType mDetailType;
        [SerializeField, Header("展示type半径")]
        private float mDetailTypeRadius = 100;
        public static GlobalAssets Inst { get; private set; }
#endif
        private void Awake()
        {
            
#if UNITY_EDITOR
            Inst = this;
#endif
            
            if (Application.isPlaying == false)
                return;

            SceneBox.OnGlobalAssetLoaded(this);
            
        }

        // private Dictionary<int, SceneObj.BaseMoveAbleObj> _moveAbleObjs =
        //     new Dictionary<int, SceneObj.BaseMoveAbleObj>(300);
        private void LateUpdate()
        {
            
        }

        private void OnDrawGizmos()
        {
            if (Application.isPlaying)
            {
                if (mShowSceneBoxBounds)
                {
                    SceneBox.DrawGlobalGizmos();
                }
                else
                {
                    SceneBox.DrawViewGizmos(mDetailType,mDetailTypeRadius);
                }
                return;
            }

            Gizmos.color = Color.white;
            foreach (var data in mGlobalBoxes)
            {
                Gizmos.DrawWireCube(data.BoxBounds.center, data.BoxBounds.size);
            }

            Gizmos.color = Color.red;
            foreach (var point in mGlobalPoints)
            {
                Gizmos.DrawSphere(point.PointBound.center, 5);
            }

            Gizmos.color = Color.yellow;
            Gizmos.DrawWireCube(_sceneBounds.center, _sceneBounds.size);

            Gizmos.color = Color.blue;
            Gizmos.DrawWireSphere(SceneBox.ViewCenter,1000);
        }

#if UNITY_EDITOR
        public void EditorAdd(Bounds sceneBounds, List<SceneBox.ScenePoint> list1, List<SceneBox> list2)
        {
            _sceneBounds = sceneBounds;
            mGlobalPoints = new List<SceneBox.ScenePoint>(list1.Count);
            mGlobalPoints.AddRange(list1.ToArray());
            mGlobalBoxes = new List<SceneBox>(list2.Count);
            mGlobalBoxes.AddRange(list2.ToArray());
        }
#endif

        public List<SceneBox.ScenePoint> GetPointAssets()
        {
            return mGlobalPoints;
        }

        public List<SceneBox> GetBoxAssets()
        {
            return mGlobalBoxes;
        }
    }
}